﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QuanLyNhaSach.QuanLyNhaSachDTO;

namespace QuanLyNhaSach.QuanLyNhaSachDao
{
    class PhieuNhapsachDao
    {
        public static DataTable GetPhieuNhapSachAll()
        {
            string sql = "select* from PhieuNhapSach where Active=True";
            return Database.ExcuQuery(sql);
        }
        public static DataTable GetPhieuNhapSachTheoMaPhieu(int ma)
        {
            int ma1 = Convert.ToInt32(ma);
            string sql = "select* from PhieuNhapSach where Active=True and MaPhieuNhap=" + ma1 + "";
            return Database.ExcuQuery(sql);
        }
        public static bool Insert(PhieuNhapSachDTO pn)
        {
            string sql;
            bool active = true;


            sql = "insert into PhieuNhapSach(NgayNhap,Active) values('" + pn.NgayNhap + "'," + active + ")";

            Database.ExcuNonQuery(sql);
            return true;


            return false;

        }
        public static bool Delete(PhieuNhapSachDTO pn)
        {
            bool active = false;
            string sql = "delete from PhieuNhapSach  where MaPhieuNhap=" + pn.MaPhieuNhap + "";
            Database.ExcuNonQuery(sql);
            return true;
        }
        public static bool Update(PhieuNhapSachDTO pn)
        {
            string sql = "Update  PhieuNhapSach set NgayNhap= ('" + pn.NgayNhap + "') where MaPhieuNhap = " + pn.MaPhieuNhap + "";

            Database.ExcuNonQuery(sql);
            return true;
        }
       
    }
}
